package com.informatica.test.gwt.server;
import java.io.InputStream;
import java.util.Properties;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;

import com.informatica.test.gwt.server.UserContext;
import com.informatica.test.gwt.server.Configuration;

public class JobDelegate {

private final static String CONF_FILE_NAME = "config.properties";
    
    private ObjectMapper objectMapper;
    private UserContext context;
    private Configuration configuration;
	
	
   
    JobDelegate application = new JobDelegate();
    public JobDelegate() {
    }
    
	

        

    public String run() {
    	Properties confProps = new Properties();
    	application.setConfiguration(configuration);
    	application.setObjectMapper(new ObjectMapper());
    	application.setContext(new UserContext());
    	try {
    	            InputStream in = JobDelegate.class.getClassLoader().getResourceAsStream(CONF_FILE_NAME);
    	            confProps.load(in);
    	            Configuration configuration = new Configuration(confProps);
    	} catch (Exception ex) {
    	            System.out.println("Cannot load " + CONF_FILE_NAME);
    	            System.exit(1);
    	}
    	BaseDelegate BD=new BaseDelegate(configuration,new ObjectMapper(),new UserContext());

    	JsonNode PostLogin=BD.post("/v2/user/login?login={0}&password={1}", "yurova92@gmail.com", "ghbdtnbr");
    	JsonNode myTask=BD.post("v2/job?taskId={0}&taskType={1}", 15, "MTT");

      return myTask.get("@type").toString();
    }

 

    public ObjectMapper getObjectMapper() {
        return objectMapper;
    }

    public void setObjectMapper(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    public UserContext getContext() {
        return context;
    }

    public void setContext(UserContext context) {
        this.context = context;
    }

    public Configuration getConfiguration() {
        return configuration;
    }

    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }

}
